package com.cheung.leetcode.hash;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.hash
 * @Author :  cheungming
 * @CreateTime : 2024-05-01 10:01:12
 * @Description : hash表242题
 * @Version : 1.0
 */
public class Code242Test {

    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        int[] res = new int[26];
        for (int i = 0; i < s.length(); i++) {
            res[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < t.length(); i++) {
            res[t.charAt(i) - 'a']--;
        }

        for (int re : res) {
            if (re != 0) {
                return false;
            }
        }

        return true;

    }

    @Test
    void test1() {
        String s = "anagram", t = "nagaram";
        assert isAnagram(s, t);
    }

    @Test
    void test2() {
        String s = "rat", t = "car";
        assert !isAnagram(s, t);
    }

    @Test
    void test3() {
        String s = "ab", t = "a";
        assert !isAnagram(s, t);
    }
}
